UTL 您所在的位置:网站首页 oracle utl_url UTL

UTL

2023-09-18 03:16| 来源: 网络整理| 查看: 265

This overloaded procedure provides persistent connection support. Descriptions of the different functionality are given in the syntax declarations.

See Also:

HTTP Requests and HTTP Requests Subprograms

Syntax

Sets whether future HTTP requests should support the HTTP 1.1 persistent connection or not, and the maximum numbers of persistent connections to be maintained in the current database user session.

UTL_HTTP.SET_PERSISTENT_CONN_SUPPORT( enable IN BOOLEAN DEFAULT FALSE, max_conns IN PLS_INTEGER DEFAULT 0);

Enables or disables support for the HTTP 1.1 persistent-connection in the request.

UTL_HTTP.SET_PERSISTENT_CONN_SUPPORT( r IN OUT NOCOPY req, enable IN BOOLEAN DEFAULT FALSE);

Parameters

Table 276-54 SET_PERSISTENT_CONN_SUPPORT Procedure Parameters

Parameter Description

enable

TRUE to keep the network connection persistent. FALSE otherwise.

maximum_conns

Maximum number of connections

r

The HTTP request

Usage Notes

If the persistent-connection support is enabled for an HTTP request, the package will keep the network connections to a Web server or the proxy server open in the package after the request is completed properly for a subsequent request to the same server to reuse for each HTTP 1.1 protocol specification. With the persistent connection support, subsequent HTTP requests may be completed faster because the network connection latency is avoided. If the persistent-connection support is disabled for a request, the package will always send the HTTP header "Connection: close" automatically in the HTTP request and close the network connection when the request is completed. This setting has no effect on HTTP requests that follows HTTP 1.0 protocol, for which the network connections will always be closed after the requests are completed.

When a request is being made, the package attempts to reuse an existing persistent connection to the target Web server (or proxy server) if one is available. If none is available, a new network connection will be initiated. The persistent-connection support setting for a request affects only whether the network connection should be closed after a request completes.

Use this procedure to change the persistent-connection support setting a request inherits from the session default setting.

Users should note that while the use of persistent connections in UTL_HTTP may reduce the time it takes to fetch multiple Web pages from the same server, it consumes precious system resources (network connections) in the database server. Also, excessive use of persistent connections may reduce the scalability of the database server when too many network connections are kept open in the database server. Network connections should be kept open only if they will be used immediately by subsequent requests and should be closed immediately when they are no longer needed. Set the default persistent connection support as disabled in the session, and enable persistent connection in individual HTTP requests as shown in "Examples".

The default value of the maximum number of persistent connections in a database session is zero. To truly enable persistent connections, you must also set the maximum number of persistent connections to a positive value or no connections will be kept persistent.

Note that if you want to use persistent connections, you must call the overload that takes the maximum_conns parameter prior to calling the BEGIN_REQUEST Function, otherwise persistent connections will not be enabled for the current request even if the other form of SET_PERSISTENT_CONN_SUPPORT is called.

Examples

Using SET_PERSISTENT_CONN_SUPPORT in http requests at the session level, showing the active persistent connection after each request

DECLARE pieces utl_http.html_pieces; conns utl_http.connection_table; BEGIN -- Turns on persistent connection support for the request_pieces call. utl_http.set_persistent_conn_support(true, 1); FOR i IN 1..10 LOOP pieces := utl_http.request_pieces('http://www.example.com/'); -- Shows the active persistent connection utl_http.get_persistent_conns(conns); FOR j IN 1..conns.count LOOP dbms_output.put_line('Persistent connection '||j||': '||conns(j).host||':'||conns(j).port); END LOOP; END LOOP; -- Turns off persistent connection support. Set active max persistent connection to 0 to close all active connections. utl_http.set_persistent_conn_support(false, 0); END; /

Using SET_PERSISTENT_CONN_SUPPORT in HTTP requets showing how to use persistent connection individually in each request to fetch multiple URLs at the same host

DECLARE -- Table to store the URLs TYPE vc2_table IS TABLE OF VARCHAR2(256) INDEX BY BINARY_INTEGER; paths VC2_TABLE; PROCEDURE fetch_pages(paths IN vc2_table) AS req UTL_HTTP.REQ; resp UTL_HTTP.RESP; data VARCHAR2(1024); BEGIN -- Set the proxy server UTL_HTTP.SET_PROXY('www-proxy.example.com:80', ''); FOR i IN 1..paths.count LOOP req := UTL_HTTP.BEGIN_REQUEST(paths(i)); -- Use persistent connections except for the last request IF (i < paths.count) THEN -- Use a persistent connection for the current request UTL_HTTP.SET_PERSISTENT_CONN_SUPPORT(req, TRUE); END IF; resp := UTL_HTTP.GET_RESPONSE(req); -- Display the results of the response DBMS_OUTPUT.PUT_LINE('-'); DBMS_OUTPUT.PUT_LINE('URL: ' || paths(i)); DBMS_OUTPUT.PUT_LINE('HTTP Response Status Code: ' || resp.status_code); DBMS_OUTPUT.PUT_LINE('HTTP Response Reason Phrase: ' || resp.reason_phrase); DBMS_OUTPUT.PUT_LINE('HTTP Response Version: ' || resp.http_version); BEGIN LOOP UTL_HTTP.READ_TEXT(resp, data); -- do something with the data END LOOP; EXCEPTION WHEN UTL_HTTP.END_OF_BODY THEN NULL; END; UTL_HTTP.END_RESPONSE(resp); END LOOP; END; BEGIN -- Set a maximum of 1 persistent connection, but start with persistent connections -- off UTL_HTTP.SET_PERSISTENT_CONN_SUPPORT(FALSE, 1); -- Create a list of URLs paths(1) := 'http://www.example.com/technetwork/index.html'; paths(2) := 'http://www.example.com/us/products/index.html'; fetch_pages(paths); END; /


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有